var djbh="";	//出库申请单编号
var cgbz="";	//出馆标志
var lsbz="";	//出馆标志
var kfid="";	//库房id
var canreuse="";	//是否可以二次利用
var ids = new Array();
var checkflag = 0;

$(document).ready(function(){
	getUserRight();
	//获取Url中的参数
	djbh = GetQueryString("djbh");
	kfid = GetQueryString("kfid");
	cgbz = GetQueryString("cgbz");
	lsbz = GetQueryString("lsbz");
	
	canreuse = GetQueryString("canreuse");
	if(djbh=="" || kfid=="" || cgbz=="" || lsbz==""|| canreuse==""){
		alertFunc("参数错误！");
		return false;
	}

	//获取并填充库房责任保管员列表
  	var bgyJson = ajaxResult("get",false,ProjectName+"/sysmanage.getBgyByKfId.do",{'kfid':kfid});
  	if(bgyJson.status="ok"){
  		loadSelect("select[name=ckdjrid1],select[name=tkdsrid1]",bgyJson.rows,'userid','username');
	}else{
		alertFunc("获取保管员列表失败！");
		return false;
	}
	
	//获取并填充出库点交人2人员列表
  	var result = ajaxResult("get", false, ProjectName+"/colmanage.getOrgidByKfid.do", {'kfid':kfid});
  	if(result.status="ok"){
  		djrOrgId = result.data.orgid;
  		var bgyJson = ajaxResult("get",false,ProjectName+"/root.getUserListByOrg.do",{'orgId':djrOrgId});
  	  	if(bgyJson.status="ok"){
  	  		loadSelect("select[name=ckdjrid2],select[name=tkdsrid2]",bgyJson.rows,'userid','username');
  		}else{
  			alertFunc("获取出库点交人列表失败！");
  			return false;
  		}	
	}else{
		alertFunc("获取出库点交人列表失败！");
		return false;
	}  	
  	
	//获取并填充验放监督员列表
  	var yfjdyJson = ajaxResult("get",false,ProjectName+"/root.getUserListByRole.do",{'roleId':'yanfangjianduyuan'});
  	if(yfjdyJson.status="ok"){
  		loadSelect("select[name=ckjdrid],select[name=tkjdrid]",yfjdyJson.rows,'userid','username');
	}else{
		alertFunc("获取验放监督员列表失败！");
		return false;
	}	
	//设置返回退库藏品列表链接
    var breadcrumbHtml = '<i>当前位置：</i><li><a href="'+navAddr+'">藏品管理</a></li><li><a href="ctkList.html">出退库管理</a></li>';    
    breadcrumbHtml += '<li><a href="ctkKfList.html?djbh='+escape(djbh)+'&cgbz='+cgbz+'&lsbz='+lsbz+"&canreuse="+canreuse+'">出退库房列表</a></li><li><a href="#">出退库藏品列表</a></li>';
    $(".breadcrumb").html(breadcrumbHtml);
	var params = new Object();
	params["djbh"] = djbh;
	params["kfid"] = kfid;
	 //初始化出库验伤Table
	createTableSub('#ckys_Table',ProjectName+'/colmanage.getCkYsList.do','id',ckysTitle,params);
    createTableSub('#ck_Table',ProjectName+'/colmanage.getCkCpList.do','id',ckTitle,params);
    createTableSub('#tk_Table',ProjectName+'/colmanage.getTkCpList.do','id',tkTitle,params);
    createTableSub('#tkys_Table',ProjectName+'/colmanage.getTkYsList.do','id',tkysTitle,params);
    createTableSub('#qxck_Table',ProjectName+'/colmanage.getBckCpList.do','id',qxckTitle,params);
    createTableSub('#reuse_Table',ProjectName+'/colmanage.getEctyCpList.do','id',reuseTitle,params);
    createTable('#zyztTable',ProjectName+"/colmanage.getCtkCpzy.do",'id',zyztTitle,{'zdjh':1,'djbh':1});
	//填充出退库点交人名称
	$("select[name=ckdjrid1]").change(function(){
		if($(this).val()!=""){
			$("input[name=ckdjrmc1]").val($(this).find("option:selected").text());
		}else{
			$("input[name=ckdjrmc1]").val("");
		}
	});
	$("select[name=ckdjrid2]").change(function(){
		if($(this).val()!=""){
			$("input[name=ckdjrmc2]").val($(this).find("option:selected").text());
		}else{
			$("input[name=ckdjrmc2]").val("");
		}
	});
	$("select[name=tkdsrid1]").change(function(){
		if($(this).val()!=""){
			$("input[name=tkdsrmc1]").val($(this).find("option:selected").text());
		}else{
			$("input[name=tkdsrmc1]").val("");
		}
	});
	$("select[name=tkdsrid2]").change(function(){
		if($(this).val()!=""){
			$("input[name=tkdsrmc2]").val($(this).find("option:selected").text());
		}else{
			$("input[name=tkdsrmc2]").val("");
		}
	});
	
	//填充验放监督员名称
	$("select[name=ckjdrid]").change(function(){
		if($(this).val()!=""){
			$("input[name=ckjdrmc]").val($(this).find("option:selected").text());
		}else{
			$("input[name=ckjdrmc]").val("");
		}
	});
	$("select[name=tkjdrid]").change(function(){
		if($(this).val()!=""){
			$("input[name=tkjdrmc]").val($(this).find("option:selected").text());
		}else{
			$("input[name=tkjdrmc]").val("");
		}
	});
	
    //初始化选择人员模态框
	 tagIni();
	 isClosedObject("orgTree","selectObjectDialog");
	 
	 $('#ckysBtn').click(function(){
		 refreshTableSub('#ckys_Table',params);
		// createTableSub('#ckys_Table',ProjectName+'/colmanage.getCkYsList.do','id',ckysTitle,params);
	 })
	 $('#ckBtn').click(function(){
		 refreshTableSub('#ck_Table',params);
		 //createTableSub('#ck_Table',ProjectName+'/colmanage.getCkCpList.do','id',ckTitle,params);
	 })
	 $('#tkBtn').click(function(){
		 refreshTableSub('#tk_Table',params);
		 //createTableSub('#tk_Table',ProjectName+'/colmanage.getTkCpList.do','id',tkTitle,params);
	 })
	 $('#tkysBtn').click(function(){
		 refreshTableSub('#tkys_Table',params);
		 //createTableSub('#tkys_Table',ProjectName+'/colmanage.getTkYsList.do','id',tkysTitle,params);
	 })
	 $('#qxBtn').click(function(){
		 refreshTableSub('#qxck_Table',params);
		 //createTableSub('#qxck_Table',ProjectName+'/colmanage.getBckCpList.do','id',qxckTitle,params);
	 })
	 $('#reuseBtn').click(function(){
		 refreshTableSub('#reuse_Table',params);
	 })
	 
	 if(canreuse=="1"){
		 $("#reuseLi").show();
	 }
	 //获取用户信息，显示相应操作按钮
	 if(getUserRight()){
		 if(userInfo.roleid.indexOf("zerenbaoguanyuan")>-1){	//保管员
			 $("#ckystj_btn,#qxckys_btn,#tkystj_btn,#ectytj_btn,#wctj_btn").show();	//显示出退库验伤提交按钮
			 if(cgbz==0){
				 if(lsbz==1){
					 $("#ckqr_btn,#qxck_btn,#tkqr_btn").show();	//显示出退库确认提交按钮
				 }else{
					 $("#ckdj_btn,#qxck_btn,#dydjc_btn,#tkdj_btn").show();	//显示出退库点交提交按钮
				 }				 
			 }
		 }else if(userInfo.roleid.indexOf("yanfangjianduyuan")>-1){	//验放监督员
			 $("#cgdj_btn,#qxck_btn,#dydjc_btn,#dysbb_btn,#tgdj_btn,#dycgzh_btn,#dycjgj_btn,#dycjhz_btn,#dycjml_btn").show();	//显示出退馆点交提交按钮
		 }
	 }
	 //取消出库按钮
	 $('#qxckys_btn').click(function(){
		 openQxck_ids("ckys");
	 });
	 $('#qxck_btn').click(function(){
		 openQxck_ids("ck");
	 });
	 $('#mod_qxck_btn').click(function(){
		 qxck();
	 });
	 
	 //出库验伤完成提交
	 $("#ckystj_btn").click(function(){
		var ids = selDataIds("#ckys_Table");
		if(ids.length == 0){
			alertFunc("请选择记录！");
			return false;
		}
		bootbox.setLocale("zh_CN");
		bootbox.confirm("您确定出库验伤完成，提交进行出库吗？",function(r){
			if(r){
				var params = {'ids':ids+"",'djbh':djbh,'kfid':kfid,'canreuse':canreuse};
				var dbResult = ajaxResult("get",false,ProjectName+"/colmanage.tijiaoCkYs.do",params);
				if(dbResult["status"] == 'ok'){
				   alertFunc("出库验伤提交成功！");
				   $('#ckys_Table').bootstrapTable('refresh');
			    }else{
				   alert("出库验伤提交失败！");
				   return false;
			    }
			}
		});
	 });
	 
	//退库验伤完成提交
	 $("#tkystj_btn").click(function(){
		var ids = selDataIds("#tkys_Table");
		if(ids.length == 0){
			alertFunc("请选择记录！");
			return false;
		}
		bootbox.setLocale("zh_CN");
		bootbox.confirm("您确定退库验伤完成并提交吗？",function(r){
			if(r){
				var params = new Object();
				params["ids"]=ids.toString();
				params["djbh"]=djbh;
				params["kfid"]=kfid;
				var params = {'ids':ids+"",'djbh':djbh,'kfid':kfid,'canreuse':canreuse};
				var dbResult = ajaxResult("get",false,ProjectName+"/colmanage.tijiaoTkYs.do",params);
				if(dbResult["status"] == 'ok'){
				   alertFunc("退库验伤提交成功！");
				   $('#tkys_Table').bootstrapTable('refresh');
				   ajaxResult("post",false,ProjectName+"/colmanage.ysUnlock.do",{"djbh":djbh,"kfid":kfid});
				   window.location.href='ctkKfList.html?djbh='+djbh+'&cgbz='+cgbz+'&lsbz='+lsbz+"&canreuse="+canreuse;
			    }else{
				   alertFunc("退库验伤提交失败！");
				   return false;
			    }
			}
		});
	 });
	  
	 
	 //出库确认
	 $("#ckqr_btn").click(function(){
		if(checkcpsl()){
			bootbox.setLocale("zh_CN");
			bootbox.confirm("您确定提交出库确认吗？",function(r){
				if(r){
					if(userInfo.userid!=null && userInfo.userid!=''){
						var params = new Object();
						params["ids"]=ids+"";
						params["ckdjr1_id"]=userInfo.userid;
						params["ckdjr1_mc"]=userInfo.username;
						params["ckdjr2_id"]=userInfo.userid;
						params["ckdjr2_mc"]=userInfo.username;
						params["cktqr1_id"]=userInfo.userid;
						params["cktqr1_mc"]=userInfo.username;
						params["cktqr2_id"]=userInfo.userid;
						params["cktqr2_mc"]=userInfo.username;
						params["ckjdrid"]=userInfo.userid;
						params["ckjdrmc"]=userInfo.username;
						params["djbh"]=djbh;
						params["kfid"]=kfid;
						params["canreuse"]=canreuse;
						var dbResult = ajaxResult("get",false,ProjectName+"/colmanage.tijiaoCk.do",params);
						if(dbResult["status"] == 'ok'){
							alertFunc("出库确认提交成功！");
							$('#ck_Table').bootstrapTable('refresh');
						}else{
							alertFunc("出库确认提交失败！");
							return false;
						}
					}else{
						alertFunc("获取用户信息失败！");
					}				
				}
			});
		}
	 });
	//打开出库点交窗口
	 $("#ckdj_btn").click(function(){
		 if(checkcpsl()){
		if(getUserRight()){
			$("#ckdjModal #myLabel").text("出库点交");
			$("#form_ckdj")[0].reset();
			$("#form_ckdj input[name=ids]").val(ids);
			$("#ckdjModal").modal('show');
		}
	 }
	 });
	//打开出馆点交窗口
	 $("#cgdj_btn").click(function(){
		 if(checkcpsl()){
			 if(getUserRight()){
				 $("#cgdjModal #myLabel").text("出馆点交");
				 $("#form_cgdj")[0].reset();
				 $("#form_cgdj input[name=ids]").val(ids);
				 $("#form_cgdj #cgjdrmc").val(userInfo.username);
				 $("#form_cgdj #cgjdrid").val(userInfo.userid);
				 $("#cgdjModal").modal('show');
			 }
		 }
	 });
	 //出库点交
	 $("#mod_ckdj_btn").click(function(){

		var _ckdjr1_id=$("#_ckdjr1_id").val();
		var _ckdjr2_id=$("#_ckdjr2_id").val();
		var _cktqr1_id=$("#_cktqr1_id").val();
		var _cktqr2_id=$("#_cktqr2_id").val();
		
		if(_ckdjr1_id==""||_ckdjr2_id==""||_cktqr1_id==""||_cktqr2_id==""){
			alertFunc("用户验证未通过！");
			return false;
		}
		var params =$("#form_ckdj").serializeObject();
		if(params.ids!=null && params.ids!=""){		
			params["djbh"]=djbh;
			params["kfid"]=kfid;
			params["canreuse"]=canreuse;	
			params["ckjdrid"]=userInfo.userid;
			params["ckjdrmc"]=userInfo.username;				
			ckdjJson = ajaxResult("get",false,ProjectName+'/colmanage.tijiaoCk.do',params);
			if(ckdjJson.status == "ok"){
				alertFunc("出库点交成功！");
				$("#ckdjModal").modal('hide');
				$('#ck_Table').bootstrapTable('refresh');						
			}else{
				alertFunc("出库点交失败！");
				return false;
			}
		}		 
	 });
	 
	//出馆点交
	 $("#mod_cgdj_btn").click(function(){
		var _ckdjr1_id=$("#_cgdjr1_id").val();
		var _ckdjr2_id=$("#_cgdjr2_id").val();
		var _cktqr1_id=$("#_cgtqr1_id").val();
		var _cktqr2_id=$("#_cgtqr2_id").val();
		
		if(_ckdjr1_id==""||_ckdjr2_id==""||_cktqr1_id==""||_cktqr2_id==""){
			alertFunc("用户验证未通过！");
			return false;
		}
		var params =$("#form_cgdj").serializeObject();
		if(params.ids!=null && params.ids!=""){		
			params["djbh"]=djbh;
			params["kfid"]=kfid;
			params["canreuse"]=canreuse;	
			cgdjJson = ajaxResult("get",false,ProjectName+'/colmanage.tijiaoCg.do',params);
			if(cgdjJson.status == "ok"){
				alertFunc("出馆点交成功！");
				$("#cgdjModal").modal('hide');
				$('#ck_Table').bootstrapTable('refresh');						
			}else{
				alertFunc("出馆点交失败！");
				return false;
			}
		}		 
	 });
	 
	 //打开退馆点交窗口
	 $("#tgdj_btn").click(function(){
		 var ids = selDataIds("#tk_Table");
		 if(ids.length == 0){
			 alertFunc("请选择记录！");
			 return false;
		 }
		 if(getUserRight()){
			 $("#form_tgdj")[0].reset();
			 $("#form_tgdj #optype").val("tgdj");
			 $("#form_tgdj input[name=ids]").val(ids);
			 $("#form_tgdj input[name=tkjdrmc]").val(userInfo.username);
			 $("#form_tgdj input[name=tkjdrid]").val(userInfo.userid);
			 $("#tgdjModal").modal('show');
		 }
	 });
	 //打开退库点交窗口
	 $("#tkdj_btn").click(function(){
		 var ids = selDataIds("#tk_Table");
		 if(ids.length == 0){
			 alertFunc("请选择记录！");
			 return false;
		 }
		 if(getUserRight()){
			 $("#form_tkdj")[0].reset();
			 $("#form_tkdj #optype").val("tkdj");
			 $("#form_tkdj input[name=ids]").val(ids);
			 $("#tkdjModal").modal('show');
		 }
	 });

		 
	 //打开退库确认窗口
	 $("#tkqr_btn").click(function(){
		 var ids = selDataIds("#tk_Table");
		 if(ids.length == 0){
			 alertFunc("请选择记录！");
			 return false;
		 }
		 bootbox.setLocale("zh_CN");
		 bootbox.confirm("您确定提交退库确认吗？",function(r){
			 if(r){
				 if(userInfo.userid!=null && userInfo.userid!=''){
					 var params = new Object();
					 params["ids"]=ids+"";
					 params["tkdsr1_id"]=userInfo.userid;
					 params["tkdsr1_mc"]=userInfo.username;
					 params["tkdsr2_id"]=userInfo.userid;
					 params["tkdsr2_mc"]=userInfo.username;
					 params["tkshr1_id"]=userInfo.userid;
					 params["tkshr1_mc"]=userInfo.username;
					 params["tkshr2_id"]=userInfo.userid;
					 params["tkshr2_mc"]=userInfo.username;
					 params["tkjdrid"]=userInfo.userid;
					 params["tkjdrmc"]=userInfo.username;
					 params["djbh"]=djbh;
					 params["kfid"]=kfid;
					 params["canreuse"]=canreuse;
					 var dbResult = ajaxResult("get",false,ProjectName+"/colmanage.tijiaoTk.do",params);
					 if(dbResult["status"] == 'ok'){
						 alertFunc("退库确认提交成功！");
						 $('#tk_Table').bootstrapTable('refresh');
					 }else{
						 alertFunc("退库确认提交失败！");
						 return false;
					 }
				 }else{
					 alertFunc("获取用户信息失败！");
				 }				
			 }
		 });
	 });
	 
	 //退库点交
	 $("#mod_tkdj_btn").click(function(){
		 var check= true;
		    $("#form_tkdj input[id$=Check]").each(function(){
				if($(this).val()=='0'){
					alertFunc("用户验证未通过！");
					check = false;
					return false;
				}
			});
		    if(!check)
		    	return false;
			var params =$("#form_tkdj").serializeObject();
			if(params.ids!=null && params.ids!=""){		
				params["djbh"]=djbh;
				params["kfid"]=kfid;
				params["canreuse"]=canreuse;	
				params["tkjdrid"]=userInfo.userid;
				params["tkjdrmc"]=userInfo.username;				
				dbResult = ajaxResult("get",false,ProjectName+'/colmanage.tijiaoTk.do',params);
				if(dbResult.status == "ok"){
					alertFunc("退库点交成功！");
					$("#tkdjModal").modal('hide');
					$('#tk_Table').bootstrapTable('refresh');	
					ajaxResult("post",false,ProjectName+"/colmanage.ysUnlock.do",{"djbh":djbh,"kfid":kfid});
					window.location.href='ctkKfList.html?djbh='+djbh+'&cgbz='+cgbz+'&lsbz='+lsbz+"&canreuse="+canreuse;						
				}else{
					alertFunc("退库点交失败！");
					return false;
				}
			}		 
	 });
	 
	//退馆点交
	 $("#mod_tgdj_btn").click(function(){
		 var check= true;
		    $("#form_tgdj input[id$=Check]").each(function(){
				if($(this).val()=='0'){
					alertFunc("用户验证未通过！");
					check = false;
					return false;
				}
			});
		    if(!check)
		    	return false;
			var params =$("#form_tgdj").serializeObject();
			if(params.ids!=null && params.ids!=""){
				params["djbh"]=djbh;
				params["kfid"]=kfid;
				params["canreuse"]=canreuse;	
				dbResult = ajaxResult("get",false,ProjectName+'/colmanage.tijiaoTg.do',params);
				if(dbResult.status == "ok"){
					alertFunc("退馆点交成功！");
					$("#tgdjModal").modal('hide');
					$('#tk_Table').bootstrapTable('refresh');	
					ajaxResult("post",false,ProjectName+"/colmanage.ysUnlock.do",{"djbh":djbh,"kfid":kfid});
					window.location.href='ctkKfList.html?djbh='+djbh+'&cgbz='+cgbz+'&lsbz='+lsbz+"&canreuse="+canreuse;					
				}else{
					alertFunc("退馆点交失败！");
					return false;
				}
			}		 
	 });
	 
	//二次提用提交
	 $("#ectytj_btn").click(function(){
		 var ids = selDataIds("#reuse_Table");
			if(ids.length == 0){
				alertFunc("请选择记录！");
				return false;
			}
			bootbox.setLocale("zh_CN");
			bootbox.confirm("您确定要进行二次提用吗？",function(r){
				if(r){
					var params = new Object();
					params["ids"]=ids.toString();
					params["djbh"]=djbh;
					params["kfid"]=kfid;
					var params = {'ids':ids+"",'djbh':djbh,'kfid':kfid,'canreuse':canreuse};
					var dbResult = ajaxResult("get",false,ProjectName+"/colmanage.tijiaoEcty.do",params);
					if(dbResult["status"] == 'ok'){
					   alertFunc("二次提用提交成功！");
					   $('#reuse_Table').bootstrapTable('refresh');
					   ajaxResult("post",false,ProjectName+"/colmanage.ysUnlock.do",{"djbh":djbh,"kfid":kfid});
					   window.location.href='ctkKfList.html?djbh='+djbh+'&cgbz='+cgbz+'&lsbz='+lsbz+"&canreuse="+canreuse;
				    }else{
					   alertFunc("退库验伤提交失败！");
					   return false;
				    }
				}
			});	 	 
	 });
	 
	//完成提交
	 $("#wctj_btn").click(function(){
		 var ids = selDataIds("#reuse_Table");
			if(ids.length == 0){
				alertFunc("请选择记录！");
				return false;
			}
			bootbox.setLocale("zh_CN");
			bootbox.confirm("您确定不再提用完成并提交吗？",function(r){
				if(r){
					var params = new Object();
					params["ids"]=ids.toString();
					params["djbh"]=djbh;
					params["kfid"]=kfid;
					var params = {'ids':ids+"",'djbh':djbh,'kfid':kfid,'canreuse':canreuse};
					var dbResult = ajaxResult("get",false,ProjectName+"/colmanage.tijiaoWc.do",params);
					if(dbResult["status"] == 'ok'){
					   alertFunc("完成提交成功！");
					   $('#tkys_Table').bootstrapTable('refresh');
					   ajaxResult("post",false,ProjectName+"/colmanage.ysUnlock.do",{"djbh":djbh,"kfid":kfid});
					   window.location.href='ctkKfList.html?djbh='+djbh+'&cgbz='+cgbz+'&lsbz='+lsbz+"&canreuse="+canreuse;
				    }else{
					   alertFunc("退库验伤提交失败！");
					   return false;
				    }
				}
			});	 
	 });
})
//校验点交人是否重复
function checkdjr(djr1,djr2){
	var djr1value=$("select[name="+djr1+"]").val();
	var djr2value=$("select[name="+djr2+"]").val();
	if(djr1value==djr2value){
		$("select[name="+djr2+"]").next("span").remove();
		$("select[name="+djr2+"]").after("<span class='apendhtml' style='color: red;margin-left: 5px;'>点交人不能重复</span>");
	}else{
		$("select[name="+djr1+"]").next("span").remove();
		$("select[name="+djr2+"]").next("span").remove();
	}
}

//打开取消出库窗口
function openQxck(id,qxjd){
	$("#form_qxck")[0].reset();
	$("#form_qxck input[name=id]").val(id);
	$("#form_qxck input[name=djbh]").val(djbh);
	$("#form_qxck input[name=qxjd]").val(qxjd);
	$("#qxckModal").modal('show');
}


//打开取消出库窗口
function openQxck_ids(qxjd){
	var ids = selDataIds("#"+qxjd+"_Table");
	if(ids.length == 0){
		alertFunc("请选择记录！");
		return false;
	}
	$("#form_qxck")[0].reset();
	$("#form_qxck input[name=id]").val(ids.toString());
	$("#form_qxck input[name=djbh]").val(djbh);
	$("#form_qxck input[name=qxjd]").val(qxjd);
	$("#qxckModal").modal('show');
}

//打开占用状态窗口
function openZyzt(zdjh){
	//var zyztData = ajaxResult("get",false,ProjectName+"/colmanage.getCtkCpzy.do",{'zdjh':zdjh});
	//if(zyztData.status=="ok"){		
		var params = new Object();
		params["zdjh"] = zdjh;
		params["djbh"] = djbh;
		$("#zyztTable").bootstrapTable('refresh',{query:params});
		//createTable('#zyztTable',ProjectName+"/colmanage.getCtkCpzy.do",'id',zyztTitle,{'zdjh':zdjh});
		$("#zyztModal").modal('show');
	//}else{
	//	alertFunc("获取占用状态失败！");
	//}	
}

//取消出库
function qxck(){
	var qxjd="";
	if(checkform("#form_qxck")){
		var params =$("#form_qxck").serializeObject();
		params["djbh"]=djbh;
		params["kfid"]=kfid;
		qxjd = params["qxjd"];
		if(params.id!=null && params.id!=""){
			//取消出库
			var qxckJson = ajaxResult("get",false,ProjectName+'/colmanage.quxiaoCk.do',params);
			if(qxckJson.status == "ok"){
				alertFunc("取消出库成功！");
				$("#qxckModal").modal('hide');
				if(qxjd=="ckys"){
					$('#ckys_Table').bootstrapTable('refresh');
				}else{
					$('#ck_Table').bootstrapTable('refresh');
				}				
			}else{
				alertFunc("取消出库失败！");
				return false;
			}
		}
	}
}


function checkform(formid){
	var isCheck= true;
	//验证必输项
	$(formid+" [required='true']").each(function(){
		if($(this).val()==null || $(this).val().trim()==""){
			errorMsg = $(this).attr("errorMsg")==undefined?"该项为必填项":$(this).attr("errorMsg");			
			//$(this).attr("placeholder",errorMsg);
			$(this).next("#errorMsg").remove();
			$(this).after("<span id='errorMsg' class='apendhtml' style='color: red;margin-left: 5px;'>"+errorMsg+"</span>");
			isCheck = false;
		}else if($(this).attr("type")=="number"){
			var value = parseInt($(this).val());
			if(value<1){
				errorMsg = $(this).attr("errorMsg")==undefined?"数字须大于0":$(this).attr("errorMsg");			
				//$(this).attr("placeholder",errorMsg);
				$(this).next("#errorMsg").remove();
				$(this).after("<span id='errorMsg' class='apendhtml' style='color: red;margin-left: 5px;'>"+errorMsg+"</span>");
				isCheck = false;
			}else{
				$(this).next("#errorMsg").remove();
			}
		}else{
			$(this).next("#errorMsg").remove();
		}
	})
	return isCheck;
}
//验证用户名密码是否有效
function validateUser(formid,input1,flag){
	var userid = $("#sel_pwd_"+input1+"id").val();
	var password = $("#sel_pwd_"+input1+"pwd").val();
	if(userid!=''){
		var params = new Object();
		params["userid"] = userid;	
		params["password"] = password;
		var result = ajaxResult("get",false,ProjectName+'/root.validateUser.do',params);
		if(result.status == "ok"){
			$("#sel_pwd_"+input1+"pwd").next("span").remove();
			$("#sel_pwd_"+input1+"pwd").after("<span name='validateText' style='margin-left:5px;'>通过</span>");
			$("#"+input1+"check").val("1");
			$("#"+input1+"id").val(userid);
			if(input1.indexOf("djr")>0||input1.indexOf("dsr")>0){				
				$("#"+input1+"mc").val($("#sel_pwd_"+input1+"id").find("option:selected").text());
			}else{
				$("#"+input1+"mc").val($("#sel_pwd_"+input1+"idText").val());
			}
			checkflag = 0;
			ctk_valid_fingerveinimage(flag);
		}else{
			$("#sel_pwd_"+input1+"pwd").next("span").remove();
			$("#sel_pwd_"+input1+"pwd").after("<span name='validateText' style='color:red;margin-left:5px;'>不通过</span>");
			$("#"+input1+"check").val("0");
		}
	}
}
//验证用户名密码是否有效
function validateUser1(formid,input1,flag){
	var userid = $("#sel_pwd_"+input1+"id").val();
	var password = $("#sel_pwd_"+input1+"pwd").val();
	if(userid!=''){
		var params = new Object();
		params["userid"] = userid;	
		params["password"] = password;
		var result = ajaxResult("get",false,ProjectName+'/root.validateUser.do',params);
		if(result.status == "ok"){
			$("#sel_pwd_"+input1+"pwd").next("span").remove();
			$("#sel_pwd_"+input1+"pwd").after("<span name='validateText' style='margin-left:5px;'>通过</span>");
			$("#"+input1+"check").val("1");
			$("#"+input1+"id").val(userid);
			if(input1.indexOf("djr")>0||input1.indexOf("dsr")>0){				
				$("#"+input1+"mc").val($("#sel_pwd_"+input1+"id").find("option:selected").text());
			}else{
				$("#"+input1+"mc").val($("#sel_pwd_"+input1+"idText").val());
			}
			checkflag = 0;
//			ctk_valid_fingerveinimage(flag);
		}else{
			$("#sel_pwd_"+input1+"pwd").next("span").remove();
			$("#sel_pwd_"+input1+"pwd").after("<span name='validateText' style='color:red;margin-left:5px;'>不通过</span>");
			$("#"+input1+"check").val("0");
		}
	}
}
function checkcpsl(){
	ids = new Array();
 	var cpslValid = true;
 	var fswValid = true;
 	var selectData = $("#ck_Table").bootstrapTable('getSelections');	 	
	$.each(selectData,function(index,value){	//遍历选中的藏品，判断出库数量是否大于在库数量
		ids.push(value["id"]);
		if(value["lyztid"]>1){	//当利用主体包含附属物时，获取附属物信息
			zdjh=value["zdjh"];
			fswJson = ajaxResult("get",false,ProjectName+'/colmanage.getCtkCpfswList.do',{'zdjh':zdjh,'djbh':djbh});
			if(fswJson.status=="ok"){
				$.each(fswJson.rows,function(fswIndex,fswValue){	////遍历附属物，判断出库数量是否大于在库数量
					fswzksl = fswValue["zksl"];
					fswcksl = fswValue["cksl"];
					if(fswcksl>fswzksl){
						fswValid=false;
						return false;
					}
				});
				if(!fswValid){
					return false;
				}
			}else{
				alertFunc("获取附属物信息失败！");
				return false;
			}
		}else{
			zksl = value["zksl"];
			cksl =value["cksl"];
			if(cksl>zksl){
				cpslValid=false;
				return false;
			}
		}			
	});		
	if(ids.length == 0){
		alertFunc("请选择记录！");
		return false;
	}	
	if(!cpslValid){
		alertFunc("您选择的藏品在库数量不足，请等待其他利用申请将藏品退库后才能重新出库!");
		return false;
	}
	if(!fswValid){
		alertFunc("您选择的附属物在库数量不足，请等待其他利用申请将附属物退库后才能重新出库!");
		return false;
	}
	return true;
}
//判断点交用户是否有效
function checkuser(fromid,useridInput,isValidateInput){
	var userid= $(formid+" "+useridInput).val();
	var isValidate= parseInt($(formid+" "+isValidateInput).val());
	var result = false;
	if(userid == ""){
		return true;
	}else{
		return isValidate;
	}
}
/*
function ctk_valid_fingerveinimage(flag,val){
	if(flag=="cg"){		
		var _ckdjr1_id=$("#_"+flag+"djr1_id").val();
		var _ckdjr2_id=$("#_"+flag+"djr2_id").val();
		var _cktqr1_id=$("#_"+flag+"tqr1_id").val();
		var _cktqr2_id=$("#_"+flag+"tqr2_id").val();
		if(_ckdjr1_id==""){
			valid_fingerveinimage(val+"点交人1","_"+flag+"djr1_",flag);
		}else if(_ckdjr2_id==""){
			valid_fingerveinimage(val+"点交人2","_"+flag+"djr2_",flag);
		}else if(_cktqr1_id==""){
			valid_fingerveinimage(val+"提取人1","_"+flag+"tqr1_",flag);
		}else if(_cktqr2_id==""){
			valid_fingerveinimage(val+"提取人2","_"+flag+"tqr2_",flag);
		}else{
			alertFunc("验证完成");
		}
	}else{//退馆
		var _tkdsr1_id=$("#_"+flag+"dsr1_id").val();
		var _tkdsr2_id=$("#_"+flag+"dsr2_id").val();
		var _tkshr1_id=$("#_"+flag+"shr1_id").val();
		var _tkshr2_id=$("#_"+flag+"shr2_id").val();
		if(_tkdsr1_id==""){
			valid_fingerveinimage(val+"点收人1","_"+flag+"dsr1_",flag);
		}else if(_tkdsr2_id==""){
			valid_fingerveinimage(val+"点收人2","_"+flag+"dsr2_",flag);
		}else if(_tkshr1_id==""){
			valid_fingerveinimage(val+"送回人1","_"+flag+"shr1_",flag);
		}else if(_tkshr2_id==""){
			valid_fingerveinimage(val+"送回人2","_"+flag+"shr2_",flag);
		}else{
			alertFunc("验证完成");
		}
	}
}
*/
/**
 * 出馆，退馆需要指静脉验证
 */
function ctk_valid_fingerveinimage(flag){
	if(flag=="cg"){		
		var _ckdjr1_id=$("#_"+flag+"djr1_id").val();
		var _ckdjr2_id=$("#_"+flag+"djr2_id").val();
		var _cktqr1_id=$("#_"+flag+"tqr1_id").val();
		var _cktqr2_id=$("#_"+flag+"tqr2_id").val();
		if(_ckdjr1_id==""){
			valid_fingerveinimage("出库点交人1","_"+flag+"djr1_",flag);
		}else if(_ckdjr2_id==""){
			valid_fingerveinimage("出库点交人2","_"+flag+"djr2_",flag);
		}else if(_cktqr1_id==""){
			valid_fingerveinimage("出库提取人1","_"+flag+"tqr1_",flag);
		}else if(_cktqr2_id==""){
			valid_fingerveinimage("出库提取人2","_"+flag+"tqr2_",flag);
		}else{
			alertFunc("验证完成");
		}
	}else{//退馆
		var _tkdsr1_id=$("#_"+flag+"dsr1_id").val();
		var _tkdsr2_id=$("#_"+flag+"dsr2_id").val();
		var _tkshr1_id=$("#_"+flag+"shr1_id").val();
		var _tkshr2_id=$("#_"+flag+"shr2_id").val();
		if(_tkdsr1_id==""){
			valid_fingerveinimage("退库点收人1","_"+flag+"dsr1_",flag);
		}else if(_tkdsr2_id==""){
			valid_fingerveinimage("退库点收人2","_"+flag+"dsr2_",flag);
		}else if(_tkshr1_id==""){
			valid_fingerveinimage("退库送回人1","_"+flag+"shr1_",flag);
		}else if(_tkshr2_id==""){
			valid_fingerveinimage("退库送回人2","_"+flag+"shr2_",flag);
		}else{
			alertFunc("验证完成");
		}
	}
}

/**
 * 指静脉验证
 * @param fieldname
 * @param fieldid
 * @param flag
 * @param tmpfieldid
 */
function valid_fingerveinimage(fieldname,fieldid,flag){
	var alertmessage = "请"+fieldname+"进行指静脉验证";
	if(checkflag>0){
		alertmessage = fieldname+"验证失败，请重新进行指静脉验证！";
	}
	alertFunc(alertmessage,function(){
		var _user = verify();
		var _flag = false;
		if(_user!=null&&_user.status == "ok"){//验证成功
			var _userid = _user.data.userid;
			var _username = _user.data.username;
			if(confirm("请确认："+fieldname+"："+_username)){
				//隐藏密码验证
				$("#div_fvi_"+fieldid).show();
				$("#div_pwd_"+fieldid).hide();
				
				checkflag = 0;//验证次数清零
//				$("input[name="+tmpfieldid+"id]").val(_userid);
//				$("input[name="+tmpfieldid+"mc]").val(_username);
//				$("#"+fieldid+"mc_text").val(_username);
				
				$("#"+fieldid+"id").val(_userid);//验证成功后将验证人姓名id记录
				$("#"+fieldid+"mc").val(_username);
				$("#"+fieldid+"mc_text").val(_username);
				_flag = true;
				ctk_valid_fingerveinimage(flag);
			}
		}
		if(!_flag){//验证失败
			checkflag ++;
			if(checkflag>3){//超过3次显示密码验证
				alertFunc("指静脉验证失败超过3次, 请进行密码验证 :",function(){					
					$("#div_fvi_"+fieldid).hide();
					$("#div_pwd_"+fieldid).show();
				});
			}else{
				ctk_valid_fingerveinimage(flag);
			}
		}
	});
}

//打开藏品详细对话框
function detailWin(zdjh){
	$("#detailModal").modal("show");
	$("#cpDetailframe").attr("src","../query/zongZhangDetail.html?zdjh="+zdjh+"&type=view");
	$("#detailModal").attr("zdjh",zdjh);
}

var ckysTitle = [{
		 field: 'check',
		 checkbox:true
	    },{
	        field: 'sldz',
	        title: '代表影像',
	        formatter: function(value, row, index) {	          
	      	  if(value!=null && value!=''){
	      		  return '<img src="'+(imageAddr+value)+'" style="width:100px;height:100px;"/>';
	      	  }else{
	      		  return '<img src="../../resources/images/sun.jpg" style="width:100px;height:100px;"/>';
	      	  }    	  
	      	}
	    },{
	        field: 'zdjh',
	        title: '总登记号'
	    },  {
	        field: 'cpmc',
	        title: '藏品名称',
	        formatter: function(value, row, index) {
	        	return '<a onclick="detailWin(\''+row.zdjh+'\')">'+value+'</a>';
	        	}
	    }, {
	        field: 'lyztmc',
	        title: '利用主体'
	    },{
	        field: 'wcqk',
	        title: '完残情况'
	    },{
	        field: 'wcqk_lrsj',
	        title: '完残录入时间'
	    }, {
	        field: 'zksl',
	        title: '在库数量'
	    }, {
	        field: 'zkzt',
	        title: '占用状态',
	        formatter: function(value, row, index) {
	        	var zy = "";
	        	switch(row.zydj){
	        	case 1:
	        		zy="藏品已出库";
	        		break;
	        	case 2:
	        		zy="其他用户申请并通过审批";
	        		break;
	        	case 3:
	        		zy="其他用户已申请";
	        		break;
	        	default:
	        		break;
	        		
	        	}
	        	return '<a href="javascript:void(0)" onclick="openZyzt(\''+row.zdjh+'\')">'+zy+'</a>';
	        	}
	    }, {
	        field: 'options',
	        title: '操作',
	        formatter: function(value, row, index) {
	       		 if(userInfo.roleid.indexOf("zerenbaoguanyuan")>-1){	//保管员
	       			 return '<a href="ctkWc.html?zdjh='+row.zdjh+'&djbh='+djbh+'&kfid='+kfid+'&cgbz='+cgbz+'&lsbz='+lsbz+'">录入完残</a>&nbsp;&nbsp;&nbsp;<a href="javascript:void(0)" onclick="openQxck('+row.id+',\'ckys\')">取消出库</a>';
	       		 }else{
	       			 return '';
    			}
	      	}
	    }]
//----------------------第一页表格结束----------

var ckTitle = [{
	 field: 'check',
	 checkbox:true
   },{
       field: 'id',
       title: 'id',
       visible:false
   },{
       field: 'sldz',
       title: '代表影像',
       formatter: function(value, row, index) {
     	  if(value!=null && value!=''){
     		  return '<img src="'+(imageAddr+value)+'" style="width:100px;height:100px;"/>';
     	  }else{
     		  return '<img src="../../resources/images/sun.jpg" style="width:100px;height:100px;"/>';
     	  }    	  
     	}
   },{
       field: 'zdjh',
       title: '总登记号'
   },  {
       field: 'cpmc',
       title: '藏品名称',
       formatter: function(value, row, index) {
    	   return '<a onclick="detailWin(\''+row.zdjh+'\')">'+value+'</a>';
     	}
   }, {
       field: 'lyztmc',
       title: '利用主体'
   },{
       field: 'wcqk',
       title: '完残情况'
   },{
       field: 'wcqk_lrsj',
       title: '完残录入时间'
   },{
       field: 'ckysrmc',
       title: '出库验伤人'
   }, {
       field: 'zksl',
       title: '在库数量'
   },{
       field: 'cksl',
       title: '待出库数量'
   }, 
   {
	   field: 'zkzt',
	   title: '占用状态',
	   formatter: function(value, row, index) {
		   var zy = "";
		   switch(row.zydj){
		   case 1:
			   zy="藏品已出库";
			   break;
		   case 2:
			   zy="其他用户申请并通过审批";
			   break;
		   case 3:
			   zy="其他用户已申请";
			   break;
		   default:
			   break;
		   
		   }
		   return '<a href="javascript:void(0)" onclick="openZyzt(\''+row.zdjh+'\')">'+zy+'</a>';
	   }
   },{
       field: '',
       title: '操作',
       formatter: function(value, row, index) {
    	 if(cgbz==1){//出馆
    		 if(userInfo.roleid.indexOf("yanfangjianduyuan")>-1){	//验放监督员
      			 return '<a href="javascript:void(0)" onclick="openQxck('+row.id+',\'ck\')">取消出库</a>';
      		 }else{
      			return '';
    			}
    	 }else{	//不出馆
    		 if(userInfo.roleid.indexOf("zerenbaoguanyuan")>-1){	//保管员
      			 return '<a href="javascript:void(0)" onclick="openQxck('+row.id+',\'ck\')">取消出库</a>';
      		 }else{
      			return '';
    		}
    	 }
       }
   }]

var tkTitle = [{
	 field: 'check',
	 checkbox:true
  },{
      field: 'sldz',
      title: '代表影像',
      formatter: function(value, row, index) {
    	  if(value!=null && value!=''){
    		  return '<img src="'+(imageAddr+value)+'" style="width:100px;height:100px;"/>';
    	  }else{
    		  return '<img src="../../resources/images/sun.jpg" style="width:100px;height:100px;"/>';
    	  }    	  
    	}
  },{
      field: 'zdjh',
      title: '总登记号'
  },  {
      field: 'cpmc',
      title: '藏品名称',
      formatter: function(value, row, index) {
//    	  return '<a href="../query/zongZhangDetail.html?zdjh='+row.zdjh+'">'+value+'</a>';
      	  return '<a onclick="detailWin(\''+row.zdjh+'\')">'+value+'</a>';
    	}
  }, {
      field: 'lyztmc',
      title: '利用主体'
  }, {
      field: 'wcqk',
      title: '完残情况'
  },{
      field: 'wcqk_lrsj',
      title: '完残录入时间'
  },{
      field: 'cksl',
      title: '待退库数量'
  }, {
      field: 'gjz',
      title: '估价值'
  }, {
      field: 'cksj',
      title: '出库时间'
  },{
      field: 'ckdjrmc1',
      title: '出库点交人'
  }]

var tkysTitle = [{
	 field: 'check',
	 checkbox:true
 },{
     field: 'sldz',
     title: '代表影像',
     formatter: function(value, row, index) {
   	  if(value!=null && value!=''){
   		  return '<img src="'+(imageAddr+value)+'" style="width:100px;height:100px;"/>';
   	  }else{
   		  return '<img src="../../resources/images/sun.jpg" style="width:100px;height:100px;"/>';
   	  }    	  
   	}
 },{
     field: 'zdjh',
     title: '总登记号'
 },  {
     field: 'cpmc',
     title: '藏品名称',
     formatter: function(value, row, index) {
     	  return '<a onclick="detailWin(\''+row.zdjh+'\')">'+value+'</a>';
   	}
 }, {
     field: 'lyztmc',
     title: '利用主体'
 }, {
     field: 'wcqk',
     title: '完残情况'
 },{
     field: 'wcqk_lrsj',
     title: '完残录入时间'
 },{
     field: 'cksl',
     title: '退库数量'
 }, {
     field: 'gjz',
     title: '估价值'
 }, {
     field: 'cksj',
     title: '出库时间'
 },{
     field: 'tksj',
     title: '退库时间'
 },{
     field: 'tkdsrmc1',
     title: '退库点收人'
 }, {
     field: 'options',
     title: '操作',
     formatter: function(value, row, index) {
		 if(userInfo.roleid.indexOf("zerenbaoguanyuan")>-1){	//保管员
			 return '<a href="ctkWc.html?zdjh='+row.zdjh+'&djbh='+djbh+'&kfid='+kfid+'&cgbz='+cgbz+'&lsbz='+lsbz+'">录入完残</a>';
		 }else{
			 return '';
		}
   	}
 }]

var qxckTitle = [{
	 field: 'check',
	 checkbox:true
},{
    field: 'sldz',
    title: '代表影像',
    formatter: function(value, row, index) {
  	  if(value!=null && value!=''){
  		  return '<img src="'+(imageAddr+value)+'" style="width:100px;height:100px;"/>';
  	  }else{
  		  return '<img src="../../resources/images/sun.jpg" style="width:100px;height:100px;"/>';
  	  }    	  
  	}
},{
    field: 'zdjh',
    title: '总登记号'
},  {
    field: 'cpmc',
    title: '藏品名称',
    formatter: function(value, row, index) {
    	  return '<a onclick="detailWin(\''+row.zdjh+'\')">'+value+'</a>';
  	}
}, {
    field: 'lyztmc',
    title: '利用主体'
},{
    field: 'wcqk',
    title: '完残情况'
},{
    field: 'wcqk_lrsj',
    title: '完残录入时间'
},{
    field: 'zksl',
    title: '在库数量'
},{
    field: 'cksl',
    title: '待出库数量'
}, {
    field: 'bcktzrmc',
    title: '取消出库通知人'
}, {
    field: 'bcksj',
    title: '取消出库时间',
    
}]


var reuseTitle = [{
	 field: 'check',
	 checkbox:true
},{
    field: 'sldz',
    title: '代表影像',
    formatter: function(value, row, index) {
  	  if(value!=null && value!=''){
  		  return '<img src="'+(imageAddr+value)+'" style="width:100px;height:100px;"/>';
  	  }else{
  		  return '<img src="../../resources/images/sun.jpg" style="width:100px;height:100px;"/>';
  	  }    	  
  	}
},{
    field: 'zdjh',
    title: '总登记号'
},  {
    field: 'cpmc',
    title: '藏品名称',
    formatter: function(value, row, index) {
    	  return '<a onclick="detailWin(\''+row.zdjh+'\')">'+value+'</a>';
  	}
}, {
    field: 'lyztmc',
    title: '利用主体'
},{
    field: 'wcqk',
    title: '完残情况'
},{
    field: 'wcqk_lrsj',
    title: '完残录入时间'
},{
    field: 'zksl',
    title: '在库数量'
},{
    field: 'cksl',
    title: '待出库数量'
}]


var zyztTitle = [
{
   field: 'rwmc',
   title: '任务名称'
},{
   field: 'zyzt',
   title: '占用主体',
   formatter: function(value, row, index) {
 	  if(value==1){
 		  return '藏品';
 	  }else if(value==2){
 		  return '附属物';
 	  }else if(value==3){
 		  return '藏品以及附属物';
 	  }else{
 		  return '';
 	  }    	  
 	}
},{
   field: 'zysl',
   title: '占用数量'
},{
   field: 'yjkssj',
   title: '预计出库时间'
},{
   field: 'yjjssj',
   title: '预计退库时间'
},{
	   field: 'tybmmc',
	   title: '提用部门'
},{
   field: 'ztdj',
   title: '占用等级',
   formatter: function(value, row, index) {
 	  if(value==1){
 		  return '他人已申请';
 	  }else if(value=2){
 		  return '他人申请并通过审批';
 	  }else if(value=3){
 		  return '已出库';
 	  }else{
 		  return '';
 	  }    	  
 	}
}]
